<template>
	<view>
		<mc-framework navTitle="MES工控机" @changeLevel="changeLevel">

			<!-- 主内容 -->
			<template #content>
				<view class="contentBox">
					<view class="Box">
						<u-cell icon="setting-fill" title="料废"></u-cell>

						<view class="BoxView" v-for="(item,index) in MaterialWasteList" :key="item.BadReasonID">
							<view class="number_view">{{item.ReasonName}}</view>
							<view class="number_box">
								<u-number-box v-model="item.Qty" :min="0" :max="100"></u-number-box>

							</view>
						</view>

						<u-cell icon="setting-fill" title="工废"></u-cell>

						<view class="BoxView" v-for="(ite,idx) in IndustrialWasteList" :key="ite.BadReasonID">
							<view class="number_view">{{ite.ReasonName}}</view>
							<view class="number_box">
								<u-number-box v-model="ite.Qty" :min="0" :max="100"></u-number-box>

							</view>
						</view>
						<div class="bottom">
							<div class="right-button">
								<button @click="confirmSub" size="mini">保存</button>
							</div>
						</div>
					</view>
				</view>
			</template>
		</mc-framework>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: '',
				MaterialWasteList: [],
				MaterialWaste: '',
				IndustrialWaste: '',
				IndustrialWasteList: [],
				WasteList: []
			};
		},
		onLoad(onlod) {

			if (onlod.WasteList) {
				this.WasteList = JSON.parse(onlod.WasteList)

			}

			this.list()
			// if (onlod.WasteList) {

			// } else {
			// }
		},
		onBackPress(options) { // 监听页面返回
			if (options.from == 'navigateBack') { // 通过点击路由返回
				return false;
			} else if (options.from == 'backbutton') { // 通过外置返回
				return true;
			}
		},
		methods: {
			confirmSub() {
				let pages = getCurrentPages()
				let prevPage = pages[pages.length - 2]
				prevPage.$vm.getValue(this.WasteList, this.MaterialWasteList, this.IndustrialWasteList)
				uni.navigateBack({
					delta: 1
				})
			},

			list() {

				var that = this

				that.Request.request('getBadReasonList', {}, (ret) => {
					ret.data.ds.map(item => item.Qty = 0)
					ret.data.ds.forEach(item2 => {
						const item1 = that.WasteList.find(item1 => item1.BadReasonID === item2
							.BadReasonID);
						if (item1) {
							item2.Qty = item1.Qty;
						}
					});
					that.WasteList = ret.data.ds
					that.MaterialWasteList = ret.data.ds.filter(item => item.ProcessType == '料废')
					that.IndustrialWasteList = ret.data.ds.filter(item => item.ProcessType == '工废')
				})
			},
			changeLevel(data, row) {
				let routes = getCurrentPages(); //当前页面栈

				let backIndex = routes.length - row.length; // 计算返回页面栈数
				uni.navigateBack({
					delta: backIndex
				})

			},
		}
	}
</script>

<style lang="scss">
	.contentBox{
		width: 100%;
		height: 100%;
		overflow-y: auto;
	}
	.Box {
		width: 100%;
		height: 100%;
		overflow-y: auto;

		.BoxView {
			display: inline-block;
			width: 13.5%;
			margin: 1.5%;
			background-color: red;
			border-radius: 9%;
			border: 1px solid #ccc;
			text-align: center;
			overflow: hidden;

			.number_box {
				padding: 7% 3%;
				background-color: pink;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.number_view {
				padding: 10% 0;
			}
		}
	}

	.bottom {
		position: fixed;
		bottom: 8vh;
		right: 1%;
		width: 100%;
		// height: 5%;
		// background-color: red;
		.right-button {
			float: right;
		}
	}
</style>